﻿using System;
using System.IO;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using Maticsoft.BLL;
using Maticsoft.Model;

namespace FineUI.Examples
{
    public partial class teacher_release1 : System.Web.UI.Page
    {
        protected void ExistsPermiss(string P_Id, string P_Status)
        {
            Maticsoft.BLL.Permissions PM = new Maticsoft.BLL.Permissions();
            if (!PM.ExistsPermiss(P_Id, P_Status))
            {
                Response.Redirect("~/user_no_permission.aspx");
            }

        }

        protected void Page_Load(object sender, EventArgs e)
        {

            if (Session["UserName"] == null)
            {
                Response.Redirect("~/login.aspx");
            }
            ExistsPermiss("T002", "已授权");
            BindGrid();
        }

        public DataSet BindGrid()
        {

            string currentT_Id = Session["UserName"].ToString();
            Maticsoft.BLL.ReportTemplate RT = new Maticsoft.BLL.ReportTemplate();
            DataSet RtDate = RT.GetList("ReportTemplate.TC_Id=TeachingClass.TC_Id and TeachingClass.T_Id=Teacher.T_Id and Teacher.T_Id= '"+currentT_Id+"'");

            DataView view1 = RtDate.Tables[0].DefaultView;
            Grid1.DataSource = view1;
            Grid1.DataBind();
            return RtDate;


        }
        protected void SetTemplateStatus(string current_R_Id,string status)
        {
            //string currentUser = Session["UserName"].ToString();
            Maticsoft.BLL.ReportTemplate DocTemplate = new Maticsoft.BLL.ReportTemplate();
            Maticsoft.Model.ReportTemplate DocTemplateInfom = DocTemplate.GetModel(current_R_Id);
            DocTemplateInfom.R_Status = status;
            DocTemplate.Update(DocTemplateInfom);
        
        }

        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {

            if (e.CommandName == "ActionRelease")//发布当前报告
            {
                int key = e.RowIndex;
                string current_R_ID = BindGrid().Tables[0].Rows[key]["R_Id"].ToString();
                SetTemplateStatus(current_R_ID, "已发布");

                BindGrid();
            
            
            }
            if (e.CommandName == "ActionCancel")//取消发布
            {
                int key = e.RowIndex;
                string current_R_ID = BindGrid().Tables[0].Rows[key]["R_Id"].ToString();
                SetTemplateStatus(current_R_ID, "未发布");

                BindGrid();
            }






        }

        protected void search_btn_Click(object sender, EventArgs e)
        {

        }

        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid();
        }
    }
}